#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: shijianbo
@Email:
@Time: 2022/6/16 15:28
@File: oracle.py
"""
import jaydebeapi
from .basic import DatabaseUtil


class OracleUtil(DatabaseUtil):

    def __init__(self,user,password,ip,port=1521,**kwargs):
        self.CURSOR = {}
        if 'server' in kwargs:
            server=kwargs['server']
        else:
            server='ORCL'
        jclassname = 'oracle.jdbc.OracleDriver'
        url=f"jdbc:oracle:thin:@{ip}:{port}/{server}"
        if user.lower()=='sys':
            url+='?internal_logon=SYSDBA'
        driver_args=[user,password]
        jarFile=self.getJarFile()
        self.db=jaydebeapi.connect(jclassname,url,driver_args,jarFile)
        self.db.jconn.setAutoCommit(False)

if __name__ == '__main__':
    ...
    with OracleUtil('sys','sys','10.20.46.181',server='orclcdb') as db:
        # db.execsql("CREATE GLOBAL TEMPORARY table hspbs.\"__UAM_COMPANY_TEMP\" on commit delete rows as select * from hspbs.uam_company")
        r=db.execsql('select * from hspbs.SYS_CFG_PARAMETERS')
        print(r)